﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 数据同步 {
    public partial class MainFrm: Form {
        public MainFrm() {
            InitializeComponent();
        }

        private void but_run_Click(object sender, EventArgs e) {
            ButEna(false);
            try {
                string con_source = this.txt_con_source.Text;
                string con_target = this.txt_con_target.Text;
                SyncNavigator sync = new SyncNavigator();

                if(checkedListBox1.GetItemChecked(0)) {
                    sync.TABLE = true;
                }
                if(checkedListBox1.GetItemChecked(1)) {
                    sync.COLUMN = true;
                }
                if(checkedListBox1.GetItemChecked(2)) {
                    sync.FUNCTION = true;
                }
                if(checkedListBox1.GetItemChecked(3)) {
                    sync.VIEW = true;
                }
                if(checkedListBox1.GetItemChecked(4)) {
                    sync.TRIGGER = true;
                }
                if(checkedListBox1.GetItemChecked(5)) {
                    sync.PROCEDURE = true;
                }
                bool flg = sync.RunCode(con_source, con_target);
                if(flg) {
                    MessageBox.Show("生成同步脚本成功在桌面！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                } else {
                    MessageBox.Show("生成同步脚本失败！", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                ButEna(true);
            } catch(Exception ex) {
                MessageBox.Show("生成同步脚本失败！" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ButEna(true);
            }
        }
        public void ButEna(bool flg) {
            if(flg) {
                but_run.Text = "运行";
                but_run.Enabled = true;
            } else {
                but_run.Text = "运行中...";
                but_run.Enabled = false;
            }

        }
    }
}
